package com.lzy.global.exception;

import com.lzy.constant.ResultCodeEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

/**
 * 全局业务异常
 *
 * @author lzy by 2019/9/17 14:46
 */
@Data
@EqualsAndHashCode
@ToString
public class GlobalBusinessException extends RuntimeException {
    /**
     * 异常code
     */
    private Integer code;
    /**
     * 异常描述
     */
    private String text;

    public GlobalBusinessException(String text) {
        this.code = ResultCodeEnum.服务器异常.getCode();
        this.text = text;
    }

    public GlobalBusinessException(ResultCodeEnum codeEnum) {
        this.code = codeEnum.getCode();
        this.text = codeEnum.getText();
    }

    public GlobalBusinessException(Integer code, String text) {
        this.code = code;
        this.text = text;
    }

    public GlobalBusinessException(String message, Integer code, String text) {
        super(message);
        this.code = code;
        this.text = text;
    }

    public GlobalBusinessException(String message, Throwable cause, Integer code, String text) {
        super(message, cause);
        this.code = code;
        this.text = text;
    }

    public GlobalBusinessException(Throwable cause, Integer code, String text) {
        super(cause);
        this.code = code;
        this.text = text;
    }

    public GlobalBusinessException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace, Integer code, String text) {
        super(message, cause, enableSuppression, writableStackTrace);
        this.code = code;
        this.text = text;
    }
}
